package cn.edu.cqut.mdm.initialize;

import cn.edu.cqut.mdm.container.PublisherDispatcherContainer;
import cn.edu.cqut.mdm.core.GlobalConfigManager;
import cn.edu.cqut.mdm.core.publisherdispatcher.PublisherDispatcher;

public class PublisherDispatcherInitializer {
	public void init() {
		String publisherDispatcherNames = GlobalConfigManager.getInstance().get(GlobalConfigManager.PUBLISHER_DISPATCHERS);
		if(publisherDispatcherNames != null){
			for(String interceptorClassName : publisherDispatcherNames.split(",")){
				if(interceptorClassName == null || interceptorClassName.trim().equals(""))
					continue;
				try {
					PublisherDispatcher publisherDispatcher = (PublisherDispatcher) Class.forName(interceptorClassName).newInstance();
					PublisherDispatcherContainer.getInstance().addPublisherDispatcher(publisherDispatcher.getName(), publisherDispatcher);
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
